import { StorageService } from 'src/app/core/sotrage/storage.service';
import { ApiService, urlService } from 'src/app/core/api';
import { CoreModule } from 'src/app/core/core.module';
import { Injectable } from '@angular/core';
import { ActivatedRoute } from '@angular/router';

@Injectable({
    providedIn: CoreModule
})
export class MemberService {

    memberPageData: any;
    /**
     *
     * @param url url.ts 的接口地址：key
     * @param data 向后台提交的数据
     */
    public getAJX(url: string, data: any): any {

        const success = this.api.post(urlService('dev', url), data).toPromise().catch(err => this.api.goToWhere(err.status));
        return success;
    }
    /**
     *
     * @param data : 后台请求成功后的报文数据
     * @param isShowMsg : 请求成功后是否需要提示成功信息 false 不需要 ： {bool(需要提示),msg：string(展示的成功信息)}
     */
    public getApiSuccess(data, isShowMsg): boolean {
        return this.api.getData(data, isShowMsg);
    }

    /**
     * @param getRouterInfo() : 返回URL传递的对象
     * @param key : 需要返回的屬性名
     */
    public getRouterInfo(key: string): any {
        if (this.routerInfo.snapshot.queryParams[key]) {
            return this.routerInfo.snapshot.queryParams[key];
        } else {
            return false;
        }
    }



    constructor(
        private storage: StorageService,
        private routerInfo: ActivatedRoute,
        private api: ApiService,
    ) { }
}
